<?php
/*!
 * LostKids API PHP Library v0.1 
 * http://huali.li/
 *
 * Copyright 2011, 
 * Written By James Pang
 *  
 * Date: 2011/2/14
 */

// php5.3 $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$res_domain = 'res';
putenv('LC_ALL=zh_CN');
setlocale(LC_ALL, 'zh_CN');
// Specify location of translation tables
bindtextdomain($res_domain, ABSPATH.'locale');
bind_textdomain_codeset($res_domain , 'UTF-8' );
// Choose domain
textdomain("$res_domain");
// Translation is looking for in ./locale/zh_CN/LC_MESSAGES/res.mo now

class ResourceBundle
{
    /**
     * can have addtional vars, e.g.
     * ResourceBundle::getMsg('resKey', val1, val2, ..);
     * 
     * where resKey = "this is a resource with {0} and {1}.";
     */
	public static function getMsg($key){
        $vals = func_get_args();

        // FIXME TODO
        echo $res = self::getResource($key);
        for($i = 0, $max = count($vals) - 1; $i < $max; $i++) {
        	$res = str_replace("{$i}", $vals[$i + 1], $res);
        }
        
        return $res;
	}

	private static function getResource($key){
        return gettext($key);
    }
}
?>
